<?php defined('InNcPHP') or exit('Access Invalid!');?>

<div class="page">
  <div class="fixed-bar">
    <div class="item-title">
      <h3><?php echo $lang['ticket_cate_index_class'];?></h3>
      <?php echo $output['top_link'];?>
    </div>
  </div>
  <div class="fixed-empty"></div>
  <form id="goods_class_form" enctype="multipart/form-data" method="post">
    <input type="hidden" name="form_submit" value="ok" />
    <table class="table tb-type2">
      <tbody>
      <tr>
          <td colspan="2" class="required"><label for="parent_id"><?php echo $lang['ticket_cate_add_sup_class'];?>:</label></td>
      </tr>
      <tr class="noborder">
          <td class="vatop rowform"><select name="tc_pid" id="gc_parent_id">
                  <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                  <?php if(!empty($output['parent_list']) && is_array($output['parent_list'])){ ?>
                      <?php foreach($output['parent_list'] as $k => $v){ ?>
                          <option <?php if($output['pid'] == $v['tc_id']){ ?>selected='selected'<?php } ?> value="<?php echo $v['tc_id'];?>"><?php echo $v['tc_name'];?></option>
                      <?php } ?>
                  <?php } ?>
              </select></td>
         <!-- <td class="vatop tips"><?php /*echo $lang['ticket_cate_add_sup_class_notice'];*/?></td>-->
      </tr>
        <tr class="noborder">
          <td colspan="2" class="required"><label class="validation" for="gc_name"><?php echo $lang['ticket_cate_index_name'];?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="" name="tc_name" id="gc_name" maxlength="20" class="txt"></td>
          <td class="vatop tips"></td>
        </tr>

      <tr class="noborder">
          <td colspan="2" class="required"><label class="validation"><?php echo $lang['ticket_cate_index_subname'];?>:</label></td>
      </tr>
      <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="" name="tc_subname" maxlength="20" class="txt"></td>
          <td class="vatop tips"></td>
      </tr>

        <tr>
          <td colspan="2"><label for="pic"><?php echo '分类图片';?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><span class="type-file-box"><input type='text' name='textfield' id='textfield1' class='type-file-text' />
            <input type='button' name='button' id='button1' value='' class='type-file-button' />
            <input name="pic" type="file" class="type-file-file" id="pic" size="30" hidefocus="true" nc_type="change_pic">
            </span></td>
          <td class="vatop tips"><?php echo '建议用300px * 210px';?></td>
        </tr>
        <tr>
          <td colspan="2" class="required"><label><?php echo $lang['nc_sort'];?>:</label></td>
        </tr>
        <tr class="noborder">
          <td class="vatop rowform"><input type="text" value="0" name="tc_sort" id="gc_sort" class="txt"></td>
          <td class="vatop tips"><?php echo $lang['ticket_cate_add_update_sort'];?></td>
        </tr>
      </tbody>
      <tfoot>
        <tr>
          <td colspan="2"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
        </tr>
      </tfoot>
    </table>
  </form>
</div>
<script>
//按钮先执行验证再提交表单
$(function(){
	$('#goods_class_form').validate({
        errorPlacement: function(error, element){
            if (element.attr('id') === 'pic') {
                error.appendTo(element.parent().parent().parent().prev().find('td:first'));
            } else {
                error.appendTo(element.parent().parent().prev().find('td:first'));
            }
        },
        rules : {
            tc_name: {
                required: true,
                remote: {
                    url: 'index.php?act=ticket_category&op=check&type=tc_name',
                    type: 'get',
                    data: {
                        tc_name : function(){
                            return $('#gc_name').val();
                        },
                        tc_pid : function() {
                            return $('#gc_parent_id').val();
                        }
                    }
                }
            },
           /* tc_subname: 'required',*/
            tc_sort: {
                digits: true,
                range: [0, 255]
            },
            pic: 'required',
            tc_pid:'required',
        },
        messages : {
            tc_name : {
                required: '<?php echo $lang['ticket_cate_add_name_null'];?>',
                remote: '<?php echo $lang['ticket_cate_add_name_exists'];?>'
            },
            /*tc_subname: '<?php echo $lang['ticket_cate_add_subname_null']; ?>',*/
            tc_sort: {
                digits: '<?php echo $lang['ticket_cate_add_sort_int'];?>',
                range: '<?php echo $lang['ticket_cate_add_sort_range'];?>'
            },
            pic: {
                required: '<?php echo $lang['ticket_cate_add_pic_null'];?>'
            },
            tc_pid:'父级分类不能为空',
        }
    });

	//提交
    $("#submitBtn").click(function(){
        $("#goods_class_form").valid() && $("#goods_class_form").submit();
    });

	//图片文件选择
    $("#pic").change(function(){
        $("#textfield1").val($(this).val());
    });

});
</script>